<template>
  <div class="box">
    <h3>My Cart</h3>
    <div class="cart">
      <div class="cart_content" v-for="(item, index) in cartList" :key="index">
         <input type="checkbox" v-model="item.choose">
        <img :src="item.goods.productImage" width="12%" />
        <p>{{item.goods.productName}}</p>
        <p>￥{{item.goods.salePrice}}</p>
        <el-input-number size="mini" v-model="item.num" :min="1" :max="10"></el-input-number>
        <p style="color:red">￥{{item.goods.salePrice}}</p>

          <el-popconfirm
                      confirmButtonText="确认"
                      cancelButtonText="取消"
                      icon="el-icon-circle-check"
                      iconColor="orange"
                      title="确认删除"
                      @onConfirm="del(index)"
                    >
        <i class="el-icon-delete" slot="reference" ></i>
          </el-popconfirm>
      </div>
      <div class="total">
        <input type="checkbox" v-model="checked">全选
        <div>
          总价：￥{{$store.getters.total}}
            <el-button type="danger">结算</el-button>
        </div>
      </div>
    </div>
      
  </div>

</template>

<script>
export default {
  data() {
    return {
      num:1
    }
  },
  computed:{
    cartList(){
      return this.$store.state.cartList
    },
    checked:{
      get(){
        return this.cartList.every(item=>{
          return item.choose==true
        })
      },
      set(newVal){
        this.$store.dispatch('allChecked',newVal)
      }
    },
  },
  methods: {
    del(index){
      this.$store.dispatch('del',index)
    }
  },
};
</script>

<style scoped lang="scss">
.box{
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.cart,h3,.total{
  width: 80vw;
  margin: 10px auto;
  .cart_content{
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #eee;
    margin: 3px 0px;
    padding: 5px;
  }

}
.total{
  display: flex;
  align-items: center;
  justify-content: space-between;
  
}
</style>